package com.qing.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qing.eduservice.entity.pojo.TOrder;
import com.qing.eduservice.service.TOrderService;
import com.qing.servicebase.utils.JwtUtils;
import com.qing.servicebase.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author Yjx
 * @since 2022-09-18
 */
@RestController
@RequestMapping("/eduservice/order")
public class TOrderController {

    private final TOrderService tOrderService;

    public TOrderController(TOrderService tOrderService) {
        this.tOrderService = tOrderService;
    }

    @PostMapping("/add/{courseId}")
    public ResponseResult save(@PathVariable String courseId, HttpServletRequest request) {
        return tOrderService.saveOrder(courseId, JwtUtils.getMemberIdByJwtToken(request));
    }

    @GetMapping("/getOrder/{orderId}")
    public ResponseResult get(@PathVariable("orderId") String orderId) {
        QueryWrapper<TOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderId);
        TOrder order = tOrderService.getOne(wrapper);
        return ResponseResult.ofSuccess(order);
    }

}

